package com.banzhi.shop.utils;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.view.WindowManager;

/**
 * Created by HT on 2017/5/27.
 */

public class ASUtils {
    /**
     * 判空
     *
     * @param str
     * @return 作用：三种类型判空
     */
    public static boolean isCanUse(String str) {
        if (str == null) {
            return false;
        }
        if ("".equals(str)) {
            return false;
        }
        if ("null".equals(str)) {
            return false;
        }
        return true;
    }

    /**
     * 获取版本名
     *
     * @return
     */
    public static String getVersionName(Activity activity) {
        PackageManager manager = activity.getPackageManager();
        try {
            //第二个参数代表额外的信息，例如获取当前应用中的所有的Activity
            PackageInfo packageInfo = manager.getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES
            );
            return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 拨打电话
     *
     * @param phonenumber
     * @return
     */
    public static Intent callphone(String phonenumber) {
        Intent callphoneintent = new Intent();
        callphoneintent.setAction(Intent.ACTION_DIAL);
        Uri data1 = Uri.parse("tel:" + phonenumber);
        callphoneintent.setData(data1);
        return callphoneintent;
    }

    public static void setAlpha(float alpha, Activity activity) {
        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
        lp.alpha = alpha;
        activity.getWindow().setAttributes(lp);
    }


}
